package org.NooLab.texx;


import java.util.Map;

import org.NooLab.utilities.files.DFutils;
import org.NooLab.utilities.files.PathFinder;
import org.NooLab.utilities.logging.LogControl;
import org.NooLab.utilities.logging.PrintLog;
import org.NooLab.utilities.resources.ResourceLoader;
import org.NooLab.utilities.strings.StringsUtil;

import org.NooLab.structures.AppInstanceAbstract;
import org.NooLab.structures.ArgumentsCliReaderAbstract;
import org.NooLab.structures.ArgumentsPublicIntf;
import org.NooLab.structures.InstanceProcessControlIntf;
import org.NooLab.texx.app.up.IniProperties;
import org.NooLab.texx.app.up.TexxStartup;
import org.NooLab.texx.applet.TexxApplet;
import org.NooLab.texx.properties.TexxControlProperties;
import org.NooLab.texx.properties.TexxProperties;


/**
 * 
 * 
 * 
 * 
 *
 */
public class TexxApp {
 
	
	//=========================================================================
	public static void main(String[] args) {

		try {
			
			new TexxApp(args);
				
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		


	}
	//=========================================================================

	
	public TexxApp(String[] args){
		
		try {
			
			TexxStartup.setApplicationID("texxapp", this.getClass());

			(new App( 0, (new Arguments()).parse(args), this.getClass())).go();
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		 
	}

	
}


@SuppressWarnings("rawtypes")
class App{

	int asService = 0;

	TexxApplet iapplet ;
	TexxInstance txxInstance;
	ArgumentsPublicIntf arguments;
	
	PrintLog out ;
	DFutils fileutil = new DFutils();

	// ========================================================================
	public App( int as_service, ArgumentsPublicIntf args, Class pubClass) {	
	
		String fname = "" ; 
		
		asService = as_service ;
		
		arguments = args;
		
		// use LogControl to control output of log messages
		LogControl.globeScope = 2; // 1=local definitions  default = 2
		LogControl.Level = 2 ;     // the larger the more detailed logging... (could be really verbose!)

		out = new PrintLog(2, true) ;
		
		boolean rB = checkForAppletMode();
		
		if (rB){
			return;
		}

		
		try {
			String lastCfgFile ="" ;
			
			TexxStartup.setProjectSpaceLabel( arguments.getProjectName()) ;
			TexxStartup.setLastProjectName(arguments.getProjectName());
			
			IniProperties.loadIniFile() ;
			
			lastCfgFile = TexxStartup.getLastDataSet();
			if ((lastCfgFile==null) || (lastCfgFile.trim().length()<=1)){
				if (TexxStartup.getApplicationID().length()==0 ){
					TexxStartup.setApplicationID( this.getClass().getName().toLowerCase(),pubClass ) ;
				}
				
			}
			IniProperties.saveIniProperties() ;
			
			if (DFutils.fileExists(arguments.getConfigFile())==false){
				if ((arguments.getConfigFile().length()>0)){

					
					// lastCfgFile = IniProperties.dataSource ;
					if (arguments.getProjectName().length()==0){
						arguments.setProjectName ("default") ;
					}
					
					fname = DFutils.createPath( arguments.getHomeDir(), arguments.getProjectName()+"/config/") ;
					fname = DFutils.createPath( fname, arguments.getConfigFile()) ;
					if (DFutils.fileExists(fname)){
						arguments.setConfigFile (fname);
					}else{
						if (fileutil.filenameIsUsable(fname)){
							arguments.setConfigFile (fname);
						}
					}
				}
				
				
				
				if (DFutils.fileExists(arguments.getConfigFile())==false){

					
					createDefaultConfig();

					
					String msgstr = "you now have to edit the configuration file : \n"+ arguments.getConfigFile();
					TexxStartup.showMsg(msgstr);

					// DocoServStartup.introduceDataSet( arguments.configFile ) ;
			
					IniProperties.saveIniProperties() ;
					// copy the filename to the system clipboard
					System.exit(0);

				}else{
					
				}
				
			}
			
			IniProperties.saveIniProperties() ;
			
			_showCurrentInputSettings();
			
			
			fname=fname+" " ;
			
		} catch (Exception e) {
			e.printStackTrace();
		}

		
		
	}
	
	

	private boolean notStopped() {
		boolean rB=true; 
		
		String filename ;
		
		try{

			filename = arguments.getConfigFile() ;
			filename = StringsUtil.separateBeforeLast( filename, "/");
			filename = DFutils.createPath(filename, "stop") ;
			
			rB = DFutils.fileExists(filename)==false ;

			if (rB==false){
				fileutil.deleteFile(filename) ;
			}
		}catch(Exception e){
			
		}
		
		return rB;
	}

	private boolean checkForAppletMode() {

		boolean rB=false;
		
		if (arguments.startApplet() ){
		
			// start applet, stop this 
			// PApplet.main( new String[] { "org.NooLab.docserver.DocumentObserverApplet","a","b" });
			// PApplet applet = new PApplet();

			// see http://wiki.processing.org/w/Setting_width/height_dynamically
			iapplet = new TexxApplet();
			
			iapplet.getInstance() ;
			
			while (iapplet!=null){
				PrintLog.Delay(100);
			}
			rB=true;
		}
		return rB ;
	}

	private void createDefaultConfig() throws Exception {
		 
		String filename = "",  filstr,resourcePath;
		boolean rB;

		resourcePath = "org/NooLab/texx/resources/texx-config-xml" ;
		ResourceLoader rsrcLoader = new ResourceLoader();   
		
		rB = rsrcLoader.loadTextResource( this.getClass(), resourcePath  ) ;
		if (rB){  
			filstr = rsrcLoader.getTextResource();
			
			filename = arguments.getConfigFile() ;
			
			fileutil.manageBakFile(filename, 10);
			fileutil.writeFileSimple( filename , filstr);
			
		}else{
			throw(new Exception("unable to load resources (create-db-sql-xml) or \n"+
					            "to create a new configuration file : "+filename)) ;
		}


		
	}


	
	private void _showCurrentInputSettings(){
		String qs="";
		if (TexxStartup.isConfigAvailable()==false){
			qs = "not " ;
		}
		// String dataStore = IniProperties.dataSource;
		// sth like: D:/data/iTexx/DocumentServer/test1/config/docoserv-config.xml
		
		
		out.print(1,"current project : "+ TexxStartup.getLastProjectName());
		if (qs.length()==0){
			out.print(1,"config source   : "+ TexxStartup.getLastDataSet() ) ;
		}

	}


	
	public void go() {


		notStopped();
		
		startEngines( asService );
		
		PrintLog.Delay(2000) ;
		// we stop from the outside by writing a file "stop" to the config directory
		while (notStopped()){
			PrintLog.Delay(100) ;
		}
		txxInstance.close(0) ;

	}

	
	/**
	 * 
	 * @param somtype 0=default: simple, single run; 1=som optimizer
	 * @param lastProjectName2 
	 */
	private void startEngines( int worktype ){
		
		if (txxInstance!=null){
			return;
		}

		txxInstance = new TexxInstance( this ) ;

		if (arguments!=null){
			txxInstance.contextMode = arguments.getContextMode() ;
		
			txxInstance.homedir = arguments.getHomeDir() ;
			txxInstance.projectname = arguments.getProjectName() ;
			txxInstance.logLevel = arguments.getLogLevel() ; 
			
			txxInstance.appSecret    = (String)arguments.getMappedTopic("appsecret"); 
			txxInstance.processName  = (String)arguments.getMappedTopic("name");
			txxInstance.waitfor      = (Integer)arguments.getMappedTopic("waitfor");
			
			txxInstance.setArguments( arguments.getArgumentsObj());
			
			txxInstance.tikaPorts    = (int[])arguments.getMappedTopic("tika");
		}
		
		
		// boolean hb = txxInstance.checkForConfiguration();
		
		out.print(1,"starting project <"+ IniProperties.lastProjectName+"> ...");
		
		if (DFutils.fileExists(arguments.getSourceFileDedicated())){
			worktype=2;
			txxInstance.directsource = arguments.getSourceFileDedicated() ;
		}
		if (DFutils.folderExists(arguments.getSourceFilesByFolder())){
			worktype=3;
			txxInstance.directsource = arguments.getSourceFilesByFolder() ;
		}
		if (DFutils.fileExists(arguments.getSourceFileByListingFile())){
			worktype=4; 
			txxInstance.directsource = arguments.getSourceFileByListingFile() ;
		}
		
		// catalog
		// file="D:/data/iTexx/app/Texx/itx/data/raw/Modernism Koolhaas Junkspace v0.46.docx"
		
		if (worktype<=1){
			worktype = TexxFactory._INSTANCE_TYPE_SERVICE ;  // using a catalog, like from a db
		}else{
			worktype = TexxFactory._INSTANCE_TYPE_EXPLICIT ;
			
		}
		
		
							int oport = arguments.getOutPort();
							int iport = arguments.getInPort();

		txxInstance.prepareTcpBox(oport,iport);  // must be before the wait object !

		
		if ((txxInstance.contextMode.toLowerCase().contentEquals("itexx")) && 
			(txxInstance.waitfor>=1)){
			// waitfor-secret for testing is "adkhf-23487asdf-3487sdfr-324"
			out.print(2, "Application will wait a few seconds for final clearance...");
			txxInstance.waitfor();
		}

		if (worktype>=0){
			txxInstance.startInstance(worktype) ;
		}
		
		
	}

}


/*
-prj:itexx
-homedir:"D:/data/iTexx/app/Texx" 
-sourcemode: catalog|[ file|folder="[fpath]" ]|[list="filename"]    if file,folder then " are mandatory
-cfg:"D:/data/iTexx/app/Texx/itexx/config/texx-config.xml" 
-context:itexx
-loglevel:1

 */
@SuppressWarnings("rawtypes")
class Arguments extends ArgumentsCliReaderAbstract implements TexxArgumentsIntf{
	
	String sourceFileDedicated="",sourceFilesByFolder="",sourceFileByListingFile="";
	
	protected ArgumentsPublicIntf arguments ;
	public Map argumentsMap;

	
	// ------------------------------------------------------------------------
	@SuppressWarnings("unchecked")
	public Arguments(){
		super();
		setParent( this ) ;

		jarDir = fileutil.getUserDir();
		homeDir = DFutils.createPath( jarDir, "Texx/") ;

		//default = standalone
		contextMode = InstanceProcessControlIntf._APP_CONTEXT_ALONE ; // itexx or standalone, running user based projects	
	}
	// ------------------------------------------------------------------------

	
	String avStr, str;
	
	
	@SuppressWarnings({ "unchecked"  })
	@Override
	public ArgumentsPublicIntf parse( String[] _args ){
		
		String avStr, str;
		
		
		// jarDir = fileutil.getUserDir();
		str = fileutil.getUserHomeDir() ;
		str = IniProperties.fluidSomProjectBasePath; // before, we passed readbinpref() !
		homeDir = DFutils.createPath( str, "app/Astor/") ;
		
		
		defineArguments( new String[]{ "prj","homedir","cfg","sourcemode","size",
				                       "resume","onCompletion","tika",
				                       "startSomClients","context","waitfor",
				                       "loglevel"});
		
		try {
		
			arguments = prepareArguments( homeDir, _args ) ;

		} catch (Exception e) {
			showArguments( getDescription() );
			System.exit(0);			
		}  
		
		argumentsMap = getArgumentsMap();
		
		
		if (handlingTreatment( new String[]{"tika","tikasrv","tikaserver"})){
		
			avStr = (String)getMappedTopic( new String[]{"tika","tikasrv","tikaserver"} );
			
			tikaPorts = _acquirePorts("tika", avStr) ;
			
		}
		
		if (handlingTreatment( new String[]{"prj","proj","project"})){
		
			projectName = (String)getMappedTopic( new String[]{"prj","proj","project"} );
			
			
			TexxStartup.setLastProjectName(projectName);
			IniProperties.lastProjectName = projectName;
			
			str = IniProperties.getFluidSomProjectBasePath() ;
			if (IniProperties.getsBinPath().length()==0){
				
				str = (new PathFinder()).getAppBinPath(this.getClass(), false);
				IniProperties.setBinPath(str) ;
			}
			
			IniProperties.saveIniProperties();
			str = IniProperties.getFluidSomProjectBasePath() ;
		}
		
		int rn = remainingTopics.size();
		
		// the rest
		if (rn>0){
			for (int i=0;i<rn;i++){
				String topic = (String) remainingTopics.get(i); 
				avStr = getArgumentValueStr( new String[]{topic} );
				if (avStr.length()>0){
					
				}// sth found
			}//i->
		}
		
		if (_args.length==0){
			showArguments( getDescription() );
			System.exit(0);
		}
		
		if (defaultsRequested){
			
			homeDir     = fileutil.createpath( fileutil.getUserDir(), "Astor") ;
			projectName = "itexx" ;
			configFile  = fileutil.createpath( homeDir, "astor-config.xml") ;
			// this file will be read by DocoControlProperties.readSettings()
		}
		
				
				
		setReference( (Object)this);
		return (ArgumentsPublicIntf) this;
	}

	 
	public ArgumentsPublicIntf getArguments() {
		return arguments;
	}
	
	public boolean startApplet() {
		return appletRequested;
	}

	@Override
	protected String[] getDescription() {
	
		String[] dParts = new String[3];
		
		dParts[0] = "Values (examples) appear subsequent to the : \n"+
		        	"-prj:\"test2\"  \n"+
		        	"-homedir:\"D:/data/iTexx/app/Texx\" \n"+
		        	" \n" ;

		dParts[1] = "Default values are activated by parameter \"-default\" or \"-d\" and are set to: \n"+
			        "-prj: docoserv  \n"+
					"-homedir: <path of jar>/DocumentServer \n"+
					"\n";
		
		
		dParts[2] = "Additional Information: \n"+
		      "- The database file will be written to the folder \"<homedir>/<project name>/storage\".  \n"+
		      "- If no configuration file has been provided, a default file will be created into \n" +
		      "  the folder \"<homedir>/<project name>/config\". \n"+
		      "  Note that you then have to edit the configuration file, namely the section defining the \n"+
		      "  the folders to be observed.\n"+
		      "- You may stop the application by creating a file \"stop\" within the folder containing \n"+
		      "  the configuration file.  \n"+
		      "- The parameters for activating the notification are port numbers, (1) in, (2) out, where \n"+
		      "  the in-port allows for some udimaentary control, such like stopping the application, or \n"+
		      "  re-reading the configuration. \n"+
		      "- For starting the interactive applet version (e.g. for testing) use the \n"+
		      "  parameter \"-a\" or \"-applet\" \n\n"+" ";
		
		
		return dParts ;
	}

	@Override
	public int[] getPorts() {
		return ports;
	}

	@Override
	public int[] getServicePorts() {
		return this.servicePorts;
	}


	@Override
	public String getAppSecret() {
		return appsecret;
	}

	@Override
	public int[] getTikaPorts() {
		return tikaPorts;
	}

	
}


class TexxInstance extends AppInstanceAbstract{
	

	
	public int[] tikaPorts;
	TexxFactory    texxFactory;
	TexxProperties texxProperties;
	TexxPropertiesHandler texxPropertiesDefaults;
	
	TexxTaskIntf texxTask;
	
	boolean batchMode = false;
	int _sourcetype =0;
	
	// will be overruled for "iTexx" context
	String _algorithmsConfigPath = "D:/dev/java/texx/plugins/" ;
	// String _algorithmsConfigPath = "" ; could be any... if empty, it is searched for within Texx-folder (not implemented yet)
	String sourceForProperties = "";
	
	private String lastProjectName;
	private int instanceType=0;
	
	int gluemode = 0;
	App app;
	
	
	// ------------------------------------------------------------------------
	public TexxInstance(App app){
		
		// these two string values are just for convenience of console output, 
		// it is not used by the application itself for any control
		super( "Texx", "TexxInstance");
		
		processName = "astor";
		
		this.app = app;
		
		
		instance = this;
		out = app.out ;
		
		sourceForProperties = "" ;
		
	}

	
	
	public boolean checkForConfiguration() {
	 
		return false;
	}




	public void setSourceMode(int sourcetype) {
		_sourcetype =sourcetype ;
	}



	public void setBatchMode(int batchmode) {
		
		batchMode = batchmode>=1 ;
		// ==1 -> from directory
	}



	public void startInstance(int worktype) {


		appSecret = app.arguments.getAppSecret() ;
		
		instanceType = worktype ;
		
		lastProjectName = IniProperties.lastProjectName ;
		instanceThrd.start();
		
	}
	// ------------------------------------------------------------------------
	
	
	@Override
	protected void prepareInstance() {
		prepareTexxer();
		createStartTask();	
	}



	@Override
	protected void resumeInstance() throws Exception {
		// 
		
	}

 
	
	private void prepareTexxer(){

		/*
		 * the basic scheme is always: 
		 * 		1. create properties object (is also loading), 
		 * 		2. create factory, prepare core instance
		 * 		3. start core instance, which contains a task loop
		 *      4. create a task
		 *      5. core will accept task and dispatch to respective objects
		 *      
		 *      
		 * only in this way we will get an application, that could always be on, if needed,
		 * and acting as a service
		 * 
		 * 
		 * plugins will be loaded in <TexxPropertiesHandler>
		 */
		sourceForProperties = "" ;
		texxProperties = TexxProperties.getInstance( sourceForProperties ); // not available
		

		// necessary for instantiating persistenceSettings !!!
		texxProperties.setInstanceType();

		texxProperties.getPersistenceSettings().setPathToSomFluidSystemRootDir(homedir);
		texxProperties.getPersistenceSettings().setProjectName(projectname) ;

		texxProperties.setApplicationContext(contextMode ) ; 
		texxProperties.setSystemRootDir( this.homedir) ;
		
		
		
		if ((sourceForProperties.length()==0) || ( texxProperties.initializationOK()==false )){
		
			texxPropertiesDefaults = new TexxPropertiesHandler(texxProperties);

			explicitlySettingProperties();

		}

		texxProperties.setApplicationContext(contextMode) ;
		
		texxProperties.setTikaPorts( tikaPorts ) ;
		//   adjust root here, before creating TexxDataBase

		
		String systemroot = texxProperties.getSystemRootDir();   // [path]/iTexx
		
		systemroot = "";
		
		PrintLog.Print(2,"\nsystemroot in properties first was : "+systemroot+"\n");
		
		systemroot = adjustSystemRootFolder(systemroot,"itexx");
		
		PrintLog.Print(2,"\nsystemroot in properties is now : "+systemroot+"\n");
		PrintLog.Delay(1500);
		// now we could save the settings for ensuring smooth restart capabilities

		// int vi = LogControl.Level;
		
		texxFactory = TexxFactory.get(texxProperties);   // creating the factory;
		
		texxFactory.out.setLogControlLevel(logLevel);
		
		
		texxFactory.saveStartupTrace( TexxFactory._INSTANCE_TYPE_DEFAULT, 
									  texxPropertiesDefaults.getStartupTraceInfo() );

		
		
		texxProperties.save();
		
		
		
	}


	private String adjustSystemRootFolder(String systemroot, String namepattern) {
		// 

		if (DFutils.folderExists(homedir)==false){
			return systemroot;
		}

		if ((systemroot.length()<=3) || 
			(DFutils.folderExists(systemroot)==false) || 
			(systemroot.toLowerCase().indexOf("/"+namepattern)<=3)){
			// systemroot = (new PathFinder()).getAppBinPath( this.getClass(), false);
			// systemroot = DFutils.getParentDir(systemroot) ;
			
			systemroot = homedir;
			
			// systemroot = DFutils.getParentDir(systemroot,1);
			
			String binpath = DFutils.getParentDir(systemroot,2);
			binpath = DFutils.createPath(binpath, "bin/") ;
			
			PrintLog.Print(2, "\nthe bin path is now known as : "+binpath );
			systemroot = DFutils.getParentDir(systemroot,2);
			
			// 
			
			IniProperties.fluidSomProjectBasePath = binpath;
			IniProperties.saveIniProperties() ;
			
			texxProperties.setSystemRootDir(systemroot) ;
			texxProperties.getPersistenceSettings().setPathToSomFluidSystemRootDir(systemroot) ;
		}

		
		return systemroot;
	}



	private void createStartTask(){
	

		// reading the file "taskscheme.xml" in "<rootdir>/<project>/model"
		TexxControlProperties cp = texxProperties.getControlProperties();
		cp.readSettings(""); // if no file is given, the default name and location will be assumed

		// this contains directory settings, mode of operation (instance, service), inclusions, exclusions

		texxTask = (TexxTaskIntf)texxFactory.createTask( TexxProperties._WORKER_TYPE_DEFAULT, TexxFactory._INSTANCE_TYPE_DEFAULT ); 
		

		texxTask.setContinuity( 1,1) ;   // param1: Level of Spela looping: 1=simple model, 2=checking 
					// 						param2: number of runs: (1,1) building a stable model, then stop 
					//               			(2,500) including screening S1, S2, max 500 steps in S2
					//                         	(2,3,500) max 3 levels in S1
					//      					(2,0,500) no dependency screening, just evo-optimizing
      

		texxTask.setStartMode(1) ;             		// default=1 == starting after producing the FluidSom
			//        <1 == only preparing, incl. 1 elementary run to load the data, 
			//              but not starting the modeling process (v switches in the middle between 3..100)
			//        >100  minimum delay in millis


		texxTask.setBatchMode( batchMode) ;
		
		if (instanceType>=2){
			texxProperties.setDataSrcFilename( directsource );
			_sourcetype = TexxTaskIntf._TEXXTASK_SOURCE_TYPE_FILE ;
		}else{
			_sourcetype = TexxTaskIntf._TEXXTASK_SOURCE_TYPE_DB  ;
		}
		texxTask.setSourceType( _sourcetype ) ;  
		
		// String str=texxProperties.getPersistenceSettings().getPathToSomFluidSystemRootDir();
		// str=texxProperties.getSystemRootDir();
		
		
		try {
			
			texxFactory.testingTikaServerConnection();
			texxFactory.produce( texxTask );
							// this produces the SomFluid and the requested som-type according to
							// SomFluidProperties._SOMTYPE_MONO, referring implicitly to sfTask; 
			
		} catch (Exception e) {
			e.printStackTrace();
		}          		
		
	 	// if we like to have graphical output, then start the applet for displaying it and 
		// define shake hands by means of GlueClients...

	}
	
	
	
	private void explicitlySettingProperties(){
		
		// PersistenceSettings ps;


		
		try {
			// important to identify the startup trace...
			String instance = "txx";
			
			texxPropertiesDefaults.setInstance( instance ,0 ); 
			
			
			
			texxPropertiesDefaults.setDataSourcing( "file",0) ; 						// "file", "db", "xml", [0|1] = online learning switch on/off
			texxPropertiesDefaults.setDataSourceName( IniProperties.dataSource );

			// String folder = texxPropertiesDefaults.getSupervisedDirectory();  		// ... also available: setSupervisedDirectory(""); 

			
			
			if (texxProperties.getApplicationContext().contentEquals(TexxProperties._APP_CONTEXT_ITEXX)){
				String str = texxProperties.getSystemRootDir();
				str = DFutils.getParentDir(str, 2);
				_algorithmsConfigPath = DFutils.createPath( str,"/bin/plugins/texx/") ;
				// 
				int n=DFutils.listOfFiles("", "jar", _algorithmsConfigPath+"transforms/" ).size();
				if (n==0){
					System.err.println("There are no potential plugins at the expected path: \n"+
							           " - "+_algorithmsConfigPath);
				}
			}
			
			// optional, if there are indeed plugin files ...
			texxPropertiesDefaults.setAlgorithmsConfigPath( _algorithmsConfigPath);
			
			

			
			// texxProperties.addFilter( "var",0.3,"<",1,1,true);       
									// filter that act on the values of observations
			   						// can be defined only with an existing factory since we need access to the data
			   						// !! not yet functional

			
			texxPropertiesDefaults.initializeDefaults();
			
			
			// controlling the granularity/verbosity of console messages 
			if (LogControl.Level>2){
				texxProperties.setShowSomProgress( TexxProperties._TXX_DISPLAY_PROGRESS_STEPS ) ; // default: _SOMDISPLAY_PROGRESS_BASIC
			}
			texxProperties.setShowSomProgress( TexxProperties._TXX_DISPLAY_PROGRESS_STEPS );
			
			texxProperties.setMultiProcessingLevel(0); 
			
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("The system will exit.");
			System.exit(-7) ;
		}
		
		// --- --- ---

		/*
		 * in this folder there will be enumerated sub-folders containing the results
		 */
		String resultFolder = texxPropertiesDefaults.setResultsPersistence(1);	// optionally: a dedicated path
		       resultFolder = texxPropertiesDefaults.getResultBaseFolder();
		       out.print(4, "" + resultFolder) ;
		// set ready flag
		texxProperties.setInitializationOK(true) ;						
	}
	
	
}










